import java.util.regex.Pattern;
/**
 * Created by Frank
 * 使用正则表达式在文本中查找换行符
 */
public class NLMatch {
    public static void main(String[] args) {
        String input = "I dream of engines\nmore engines, all day long";
        System.out.println("INPUT:" + input);
        System.out.println();
        String[] patt = {"engines.more engines", "ines\nmore", "engines$"};
        for (int i = 0; i < patt.length; i++) {
            System.out.println("PATTERN:" + patt[i]);
            boolean found;
            Pattern p1l = Pattern.compile(patt[i]);
            found = p1l.matcher(input).find();
            System.out.println("DEFAULT match " + found);
            // .代表任何符号（DOT ALL），
            Pattern pml = Pattern.compile(patt[i], Pattern.DOTALL | Pattern.MULTILINE);
            found = pml.matcher(input).find();
            System.out.println("Multiline match " + found);
            System.out.println();
/*
 运行结果：

DEFAULT match true
Multiline match true

PATTERN:engines$
DEFAULT match false
Multiline match true

 */
        }
    }
}
